home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6617 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: access1.digex.net!not-for-mail
  2. From: ell@access1.digex.net (Ell)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Interface vs. Implementation Inheritance
  5. Date: 10 Feb 1996 06:30:46 GMT
  6. Organization: The Universe
  7. Message-ID: <4fhe2m$89v@news4.digex.net>
  8. NNTP-Posting-Host: access1.digex.net
  9. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  10.  
  11.  K. Lewis (lewikk@grasshopper.aud.alcatel.com) wrote: 
  12. : When I think of substitutability, I think of subtyping.  I think a
  13. : type is substitutable for its supertype, eg, "everywhere I use a
  14. : rectangle I can use a square because a square _is a_ rectangle."
  15.  
  16. Not every class in C++ that is derived from a base class, and assigned to
  17. a base class pointer is required to, or should be a logical "is-a" subtype
  18. of the base class.  As the C++ FAQ book points out, publicly inherited
  19. classes need only satisfy the promises given by, and require no more than
  20. the base class.  [However, it is true that most publicly derived C++
  21. classes will in fact be logical "is-a" subtypes of the base.]
  22.  
  23. The point I make is that we can also view a system as having dynamically
  24. substitutable parts.  Whether by using a base class pointer as above in
  25. C++, or interface specification (contracts, or protocols) a la CLOS, and
  26. Smalltalk, the parts of a system may be changed during run-time
  27. (dynamically).  Such changes may occur on both a micro (object) and macro
  28. (subsystem/category) level.  This allows a system to fulfill more than one
  29. purpose, and to be robust in the face of widely varying run-time
  30. circumstances. 
  31.  
  32. With respect to C++, sometimes the thing we want to do with a system is to
  33. substitute one, or more of its parts with existing parts in the
  34. environment without regard to whether, or not the parts being swapped in
  35. are logical "is-a" subtypes of the base pointer being used to do the
  36. swapping.  In C++ to do such swapping, the classes being swapped must be
  37. physically inherited siblings of the base class.  In other languages,
  38. objects need only possess the protocol which allows them to be used in a
  39. given context (or to paraphrase one Internet contributor, to be used in a
  40. given "socket").  They do not have to be "is-a" subtypes of one or another
  41. class. 
  42.  
  43. Cheers,
  44.  
  45. Elliott
  46.